﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NCMIS.ObjectModel;
using NCMIS.ObjectModel.MetaData;

namespace NCMIS.Client
{
    /// <summary>
    /// Convenience class for creating CMIS object properties.
    /// </summary>
    public static class PropertyFactory
    {
        // Id of the base object-type for the object
        public static CmisProperty CreateBaseTypeId(string value)
        {
            return new CmisPropertyId()
            {
                DisplayName = "Base Type Id",
                LocalName = "BaseTypeId",
                PropertyDefinitionId = CmisPropertyDefinitionId.BaseTypeId,
                QueryName = CmisPropertyDefinitionId.BaseTypeId,
                Value = new string[] { value }
            };
        }

        // Name of the object
        public static CmisPropertyString CreateName(string value)
        {
            return new CmisPropertyString()
            {
                DisplayName = "Name",
                LocalName = "Name",
                PropertyDefinitionId = CmisPropertyDefinitionId.Name,
                QueryName = CmisPropertyDefinitionId.Name,
                Value = new string[] { value }
            };
        }

        // Id of the object
        public static CmisProperty CreateObjectId(string value)
        {
            return new CmisPropertyId()
            {
                DisplayName = "Object Id",
                LocalName = "ObjectId",
                PropertyDefinitionId = CmisPropertyDefinitionId.ObjectId,
                QueryName = CmisPropertyDefinitionId.ObjectId,
                Value = new string[] { value }
            };
        }

        // Id of the object's type
        public static CmisProperty CreateObjectTypeId(string value)
        {
            return new CmisPropertyId()
            {
                DisplayName = "Object Type ID",
                LocalName = "ObjectTypeId",
                PropertyDefinitionId = CmisPropertyDefinitionId.ObjectTypeId,
                QueryName = CmisPropertyDefinitionId.ObjectTypeId,
                Value = new string[] { value }
            };
        }

        // User who created the object
        public static CmisProperty CreateCreatedBy(string value)
        {
            return new CmisPropertyString()
            {
                DisplayName = "Created By",
                LocalName = "CreatedBy",
                PropertyDefinitionId = CmisPropertyDefinitionId.CreatedBy,
                QueryName = CmisPropertyDefinitionId.CreatedBy,
                Value = new string[] { value }
            };
        }

        // DateTime when the object was created
        public static CmisProperty CreateCreationDate(DateTime value)
        {
            return new CmisPropertyDateTime()
            {
                DisplayName = "Creation Date",
                LocalName = "CreationDate",
                PropertyDefinitionId = CmisPropertyDefinitionId.CreationDate,
                QueryName = CmisPropertyDefinitionId.CreationDate,
                Value = new DateTime[] { value }
            };
        }

        // File name of the content stream
        public static CmisProperty CreateContentStreamFileName(string value)
        {
            return new CmisPropertyString()
            {
                DisplayName = "Content Stream File Name",
                LocalName = "ContentStreamFileName",
                PropertyDefinitionId = CmisPropertyDefinitionId.ContentStreamFileName,
                QueryName = CmisPropertyDefinitionId.ContentStreamFileName,
                Value = new string[] { value }
            };
        }

        // Id of the stream
        public static CmisProperty CreateContentStreamId(string value)
        {
            return new CmisPropertyId()
            {
                DisplayName = "Content Stream Id",
                LocalName = "ContentStreamId",
                PropertyDefinitionId = CmisPropertyDefinitionId.ContentStreamId,
                QueryName = CmisPropertyDefinitionId.ContentStreamId,
                Value = new string[] { value }
            };
        }

        // Length of the content stream (in bytes)
        public static CmisProperty CreateContentStreamLength(int value)
        {
            return new CmisPropertyInteger()
            {
                DisplayName = "Content Stream Length",
                LocalName = "ContentStreamLength",
                PropertyDefinitionId = CmisPropertyDefinitionId.ContentStreamLength,
                QueryName = CmisPropertyDefinitionId.ContentStreamLength,
                Value = new int[] { value }
            };
        }

        // MIME type of the content stream
        public static CmisProperty CreateContentStreamMimeType(string value)
        {
            return new CmisPropertyString()
            {
                DisplayName = "Content Stream MIME Type",
                LocalName = "ContentStreamMimeType",
                PropertyDefinitionId = CmisPropertyDefinitionId.ContentStreamMimeType,
                QueryName = CmisPropertyDefinitionId.ContentStreamMimeType,
                Value = new string[] { value }
            };
        }

        // TRUE if the repository MUST throw an error at any attempt to update or delete
        // the object
        public static CmisProperty CreateIsImmutable(bool value)
        {
            return new CmisPropertyBoolean()
            {
                DisplayName = "Is Immutable",
                LocalName = "IsImmutable",
                PropertyDefinitionId = CmisPropertyDefinitionId.IsImmutable,
                QueryName = CmisPropertyDefinitionId.IsImmutable,
                Value = new bool[] { value }
            };
        }

        // TRUE if the Document object is the latest major version in its version series.
        public static CmisProperty CreateIsLatestMajorVersion(bool value)
        {
            return new CmisPropertyBoolean()
            {
                DisplayName = "Is Latest Major Version",
                LocalName = "IsLatestMajorVersion",
                PropertyDefinitionId = CmisPropertyDefinitionId.IsLatestMajorVersion,
                QueryName = CmisPropertyDefinitionId.IsLatestMajorVersion,
                Value = new bool[] { value }
            };
        }

        // TRUE if there currently exists a PWC for this version series.
        public static CmisProperty CreateIsVersionSeriesCheckedOut(bool value)
        {
            return new CmisPropertyBoolean()
            {
                DisplayName = "Is VersionSeries Checked Out",
                LocalName = "IsVersionSeriesCheckedOut",
                PropertyDefinitionId = CmisPropertyDefinitionId.IsVersionSeriesCheckedOut,
                QueryName = CmisPropertyDefinitionId.IsVersionSeriesCheckedOut,
                Value = new bool[] { value }
            };
        }

        // User who last modified the object
        public static CmisProperty CreateLastModifiedBy(string value)
        {
            return new CmisPropertyId()
            {
                DisplayName = "Last Modified By",
                LocalName = "LastModifiedBy",
                PropertyDefinitionId = CmisPropertyDefinitionId.LastModifiedBy,
                QueryName = CmisPropertyDefinitionId.LastModifiedBy,
                Value = new string[] { value }
            };
        }

        // DateTime when object was last modified
        public static CmisProperty CreateLastModificationDate(DateTime value)
        {
            return new CmisPropertyDateTime()
            {
                DisplayName = "Last Modification Date",
                LocalName = "LastModificationDate",
                PropertyDefinitionId = CmisPropertyDefinitionId.LastModificationDate,
                QueryName = CmisPropertyDefinitionId.LastModificationDate,
                Value = new DateTime[] { value }
            };
        }

        // Id of the parent folder of the object
        public static CmisProperty CreateParentId(string value)
        {
            return new CmisPropertyId()
            {
                DisplayName = "Parent Id",
                LocalName = "Parent Id",
                PropertyDefinitionId = CmisPropertyDefinitionId.ParentId,
                QueryName = CmisPropertyDefinitionId.ParentId,
                Value = new string[] { value }
            };
        }

        // The fully qualified path to this folder
        public static CmisPropertyString CreatePath(string value)
        {
            return new CmisPropertyString()
            {
                DisplayName = "Path",
                LocalName = "Path",
                PropertyDefinitionId = CmisPropertyDefinitionId.Path,
                QueryName = CmisPropertyDefinitionId.Path,
                Value = new string[] { value }
            };
        }
    }
}
